<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page language="java" import="com.soft.model.*"%>
<%@ page language="java" import="java.util.*"%>
<!DOCTYPE html PUBLIC>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link rel="stylesheet" href="../../css/index.css" />
<link rel="stylesheet" href="../../css/common.css" />
<script type="text/javascript" src="../../js/jquery-3.3.1.js"></script>
<script type="text/javascript" src="../../js/common.js" /></script>
<script type="text/javascript" src="../../js/admin/ready.js" /></script>
<script type="application/javascript">
			$(document).ready(function() {
				
				$("#insert").click(function(event) {
					window.location.href="store_add";
				});
				
				$(".update").click(function(event) {
					console.log(event.currentTarget.name);
					var id = $(this).attr("selectedId");
					window.location.href="store_upd?id="+id;
				});
				
				
				$(".delete").click(function(event) {
					var id = $(this).attr("selectedId");
					var row =  $(this).parent().parent();
					console.log(event.currentTarget.name);
					showMessage("I", "您确定要删除这个记录吗？", function() {
						$.ajax({
							url:"store_del",
							data:"delIds="+id,
							type:"post",
							success:function(data){
								if(data == "ok"){
									//row.remove();
									$("#search").submit();
								}
							}
						});
						//window.location.href="store_del?id="+id;
					});
				});
				
				//分页
				$(".page-c .item").click(function(event){
					var currPage = $(this).text();
					$("#currPage").val(currPage);
					$("#search").submit();
				});
				//全选
				$("#checkAll").click(function(event){
					var isChecked = $(this).prop("checked");
					if(isChecked){
						$("input[name='checkIds']").prop("checked",true);
					}else{
						$("input[name='checkIds']").prop("checked",false);
					}
				});
				//批量删除
				$("#checkDel").click(function(event){
					var ids = $("input[name='checkIds']:checked");
					var delIds = "";
					$.each(ids,function(){
						delIds+= $(this).val()+","
					});
					showMessage("I", "您确定要删除这些记录吗？", function() {
						$.post("store_del",{delIds : delIds},function(data){
							if(data="ok"){
								//$(ids).parent().parent().remove();
								$("#search").submit();
							}
						});
					});
				});
			});
			
			var getDataByPage = function(pageInfo) {
				console.log(pageInfo);
			}
		
</script>
</head>
<body class="content-body">
	<div class="title-area bg-color-black font-normal font-white">乌托邦别墅预定管理平台>内容管理>店面管理</div>
	<div class="search-area bg-color-gray">
		<form id="search" style="float:left;" action="store_list" method="post">
			<input type="hidden" id="currPage" name="currPage" value="${currPage!=null?currPage:'1' }"/>
			<input class="row-item bg-color-white search-input" type="text" id="searchText" name="searchText" placeholder="请输入名称" value="${searchText}" />
			<select class="row-item bg-color-white search-input" name="cityId" >
				<option value="0">==选择市==</option>
			<%
				String cityIdStr = (String)request.getAttribute("cityId");
// 				System.out.println(cityIdStr);
				int cityId = cityIdStr == null ? 0 : Integer.parseInt(cityIdStr);
// 				Map<Integer,City> map_city = (Map<Integer,City>) request.getAttribute("map_city");
// 				if(map_city!=null && map_city.size()>0){
// 					if(map_city.containsKey(cityId)){
// 						String selected = "";
// 					}
// 				}
				List<City> list_city = (List<City>) request.getAttribute("list_city");
				if (list_city != null && list_city.size() > 0) {
					for (City city : list_city) {
						pageContext.setAttribute("city", city);
						String selected = "";
						if (cityId == city.getId()) {
							selected = "selected";
						}
			%>
				<option value="${city.id }" <%=selected %>>${city.cityname }</option>
			<%
					}
				}
			%>
			</select>
			<input class="row-item bg-color-white search-input" type="date" id="beginTime" name="beginTime"  value="${beginTime}" />
			<span style="font-size: small; margin-left: 5px;">-</span>
			<input class="row-item bg-color-white search-input" type="date" id="endTime" name="endTime"  value="${endTime}" />
			<button class="button-get button-item" >查询</button>
		</form>
		 <span class="button-put button-item" id="insert">新增</span>
		 <span class="button-del button-item" id="checkDel">批量删除</span>
	</div>

	<!-- store list -->
	<div class="table bg-color-gray">
		<div class="row">
			<div class="col-half">
				<div class="grid-title"><input type="checkbox" id="checkAll">ID</div>
			</div>
			<div class="col-1">
				<div class="grid-title">店面名</div>
			</div>
			<div class="col-1-half">
				<div class="grid-title">联系电话</div>
			</div>
			<div class="col-1">
				<div class="grid-title">所在城市</div>
			</div>
			<div class="col-2">
				<div class="grid-title">店面地址</div>
			</div>
			<div class="col-1">
				<div class="grid-title">添加者</div>
			</div>
			<div class="col-1-half">
				<div class="grid-title">添加时间</div>
			</div>
			<div class="col-1-half">
				<div class="grid-title">操作</div>
			</div>
		</div>
		<%
			List<Store> list_store = (List<Store>) request.getAttribute("list_store");
			if (list_store != null && list_store.size() > 0) {
				for (Store store : list_store) {
					pageContext.setAttribute("store", store);
		%>
		<div class="row row-border">
			<div class="col-half">
				<div class="grid-label"><input type="checkbox" name="checkIds" value="${store.id}">${store.id}</div>
			</div>
			<div class="col-1">
				<div class="grid-label">${store.storename}</div>
			</div>
			<div class="col-1-half">
				<div class="grid-label">${store.storeTel}</div>
			</div>
			<div class="col-1">
				<div class="grid-label">${store.city.cityname}</div>
			</div>
			<div class="col-2">
				<div class="grid-label">${store.storeAddr}</div>
			</div>
			<div class="col-1">
				<div class="grid-label">${store.user.username}</div>
			</div>
			<div class="col-1-half">
				<div class="grid-label">${store.addtime}</div>
			</div>
			<div class="col-1-half">
				<div class="update width-two grid-button button-put"
					selectedId="${store.id}">编辑</div>
				<div class="delete width-two grid-button button-del"
					selectedId="${store.id}">删除</div>
			</div>
		</div>
		<%
			}
			}
		%>
	</div>

	<!-- page_area -->
	<div class="page-area">
		<div option="front" class="option font-small font-white button-get"><<</div>
		<div class="page-list">
			<div class="page-c">
				<%
					int pageCount = (int) request.getAttribute("pageCount");
					String pageStr = (String) request.getAttribute("currPage");
					int currPage = pageStr == null ? 1 : Integer.parseInt(pageStr);
					for (int i = 1; i <= pageCount; i++) {
						String addClass = "";
						if (i == currPage) {
							addClass = "selected-item";
						}
				%>
					<div target-page="<%=(i-1)%5+1 %>" class="item font-small font-white button-get <%=addClass %>"><%=i %></div>
				<% }%>
			</div>
		</div>
		<div option="back" class="option font-small font-white button-get">>></div>
	</div>
	<span style="color: blue;font-size: 16px;">共${totalCount}条记录</span>
</body>
</html>